package com.qf.controller;

import com.qf.pojo.request.TbPermissionReq;
import com.qf.pojo.response.BaseResponse;
import com.qf.service.TbPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api("管理员权限控制器")
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    TbPermissionService tbPermissionService;
    @ApiOperation(value = "查询所有权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页",required = true,dataType = "Integer"),
            @ApiImplicitParam(name = "size",value = "当前页显示多少行数据",required = true,dataType = "Integer")
    })
    @GetMapping("/findAll")
    @RequiresPermissions({"PERMISSION_FINDALL"})
    public BaseResponse findAll(@RequestParam("page") Integer page, @RequestParam("size") Integer size){
        return tbPermissionService.findAll(page,size);
    }
    @ApiOperation("修改或新增权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tbPermissionReq",value = "权限请求对象",required = true,dataType = "TbPermissionReq")
    })
    @PostMapping("/updateOrSave")
    @RequiresPermissions({"PERMISSION_UPDATEORSAVE"})
    public BaseResponse updateOrSave(@RequestBody TbPermissionReq tbPermissionReq){
        return tbPermissionService.updateOrSave(tbPermissionReq);
    }
    @ApiOperation("根据id删除某个权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "map",value = "权限id",required = true,dataType = "Map")
    })
    @DeleteMapping("/deleteById")
    @RequiresPermissions({"PERMISSION_DELETE"})
    public BaseResponse deleteById(@RequestBody Map map){
        return tbPermissionService.deleteById(Integer.valueOf(map.get("prId").toString()));
    }
}
